// 舰船系统类型定义

import type { ResourceCost } from './resources'
import type { UnlockCondition } from './game'

export interface Ship {
  id: string
  name: string
  type: ShipType
  scale: ShipScale
  attributes: ShipAttributes
  costs: ResourceCost[]
  buildTime: number
  maintenance: ResourceCost[]
  unlockConditions: UnlockCondition[]
  upgrades: ShipUpgrade[]
  icon: string
  count: number
}

export type ShipType = 'civilian' | 'military' | 'research' | 'special'

export type ShipScale = 'tiny' | 'small' | 'medium' | 'large' | 'huge' | 'gigantic'

export interface ShipAttributes {
  crew: number
  speed: number
  armor: number
  shields: number
  hull: number
  cargo?: number
  weapons?: WeaponSystem[]
  specialAbilities?: SpecialAbility[]
}

export interface WeaponSystem {
  id: string
  name: string
  type: WeaponType
  damage: number
  range: number
  accuracy: number
  fireRate: number
  energyCost: number
}

export type WeaponType = 'kinetic' | 'energy' | 'plasma' | 'missile' | 'exotic'

export interface SpecialAbility {
  id: string
  name: string
  description: string
  type: AbilityType
  cooldown: number
  energyCost: number
  effects: AbilityEffect[]
}

export type AbilityType = 'offensive' | 'defensive' | 'utility' | 'exploration'

export interface AbilityEffect {
  type: 'damage' | 'heal' | 'buff' | 'debuff' | 'teleport' | 'cloak'
  value: number
  duration?: number
  target: 'self' | 'ally' | 'enemy' | 'area'
}

export interface ShipUpgrade {
  id: string
  name: string
  description: string
  category: UpgradeCategory
  costs: ResourceCost[]
  effects: UpgradeEffect[]
  unlockConditions: UnlockCondition[]
}

export type UpgradeCategory = 'hull' | 'engines' | 'weapons' | 'shields' | 'systems'

export interface UpgradeEffect {
  attribute: keyof ShipAttributes
  value: number
  modifier: 'add' | 'multiply'
}

export interface Fleet {
  id: string
  name: string
  ships: FleetShip[]
  formation: FleetFormation
  commander?: Commander
  location: string
  status: FleetStatus
}

export interface FleetShip {
  shipId: string
  count: number
  upgrades: string[]
}

export type FleetFormation = 'line' | 'wedge' | 'sphere' | 'wall' | 'scatter'

export interface Commander {
  id: string
  name: string
  level: number
  experience: number
  skills: CommanderSkill[]
  bonuses: CommanderBonus[]
}

export interface CommanderSkill {
  id: string
  name: string
  level: number
  maxLevel: number
  effects: UpgradeEffect[]
}

export interface CommanderBonus {
  type: 'combat' | 'exploration' | 'logistics'
  value: number
  description: string
}

export type FleetStatus = 'idle' | 'moving' | 'combat' | 'exploring' | 'mining' | 'trading'

// 舰船ID常量
export const CIVILIAN_SHIPS = {
  TRANSPORT: 'transport',
  MINING_VESSEL: 'mining_vessel',
  COLONY_SHIP: 'colony_ship',
  CARGO_HAULER: 'cargo_hauler'
} as const

export const MILITARY_SHIPS = {
  CORVETTE: 'corvette',
  DESTROYER: 'destroyer',
  CRUISER: 'cruiser',
  BATTLESHIP: 'battleship',
  DREADNOUGHT: 'dreadnought',
  CARRIER: 'carrier'
} as const

export const RESEARCH_SHIPS = {
  SCOUT: 'scout',
  EXPLORER: 'explorer',
  SCIENCE_VESSEL: 'science_vessel',
  DEEP_SPACE_PROBE: 'deep_space_probe'
} as const

export const SPECIAL_SHIPS = {
  DIPLOMATIC_VESSEL: 'diplomatic_vessel',
  SPY_SHIP: 'spy_ship',
  PLANET_KILLER: 'planet_killer',
  REALITY_WARPER: 'reality_warper'
} as const

// 舰船建造队列项
export interface ShipBuildItem {
  id: string
  shipId: string
  count: number
  startTime: number
  endTime: number
  progress: number
  shipyardId: string
}